package org.hq.service;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.hq.pojo.select.VideoSelect;
import org.hq.service.sql.MysqlManageService;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.io.File;
import java.io.IOException;

@SpringBootTest
class UpVideoMessageServiceTest {
    @Autowired
private MysqlManageService sqls;
   @Test
    void pageAllVideoSelect(){
       Page<VideoSelect> page = sqls.pageAllVideoSelect(50, 30);
     for (VideoSelect videoSelect : page.getRecords()) {
         System.out.println(videoSelect.getGroupName());
         System.out.println(videoSelect.getMenuName());
         System.out.println(videoSelect.getName());
         System.out.println(videoSelect.getId());
         System.out.println(videoSelect.getUptime());
     }


   }



    /**
     * 首页解析 用于解析标签
     */
    @Test
    public void home() throws IOException {
        String path = "K:\\qqtv\\spring\\mybatis\\tvvideo\\src\\main\\resources\\static\\home.html";

        Document doc = Jsoup.parse(new File(path), "UTF-8");
       // Document doc = Jsoup.connect("https://www.3e2ef2eb.com/Enter/home.html").get();

        // 分组 区域快 div
        Elements menu = doc.getElementsByClass("menu clearfix").first().getElementsByTag("dl");

        // 获取带有 href 属性的 a 元素
        //Elements elements = menu.select("a");
        for (Element dl : menu) {
            Element a1 = dl.getElementsByTag("dt").first().getElementsByTag("a").first();

            String a1s = a1.data();
           String s = a1s.substring(a1.data().indexOf("('")+2,a1.data().indexOf("')"));

            System.out.println(s);
            // 获取 base64 字符串 分组名
           // String tbase64 = data.




            String linkHref = a1.attr("data-url");
            System.out.println(linkHref);
            //2 级分组
            for (Element a2dd : dl.getElementsByTag("dd")) {
                Element a2 = a2dd.getElementsByTag("a").first();
                System.out.println(a2.data());


                System.out.println(a2.attr("href"));
            }


            //  String linkText = content.text();

        }


    }

}